//
//  rightBtnViewController.m
//  UI_HLJ_Frame
//
//  Created by  毕宏伟 on 15/7/2.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "rightBtnViewController.h"
#import "UMSocial.h"
@interface rightBtnViewController ()
@property(nonatomic,retain)UIWebView *webview;

@property(nonatomic,retain)NSURL *url;

@end

@implementation rightBtnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor cyanColor];
    
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"分享"] style:UIBarButtonItemStylePlain target:self action:@selector(weibo:)];

    
    self.webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-49-64)];
    
    self.webview.scalesPageToFit =YES;
    
    [self.view addSubview:self.webview];
    
    NSURL *url = [NSURL URLWithString:self.rightUrl];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.webview loadRequest:request];
    
    
    
    
    
}


- (void)weibo:(UIButton *)button
{
    NSString *str =[NSString stringWithFormat:@"咱们结婚吧精彩链接%@",self.url];
    [UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToSina];
    //进入授权页面
    [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        if (response.responseCode == UMSResponseCodeSuccess) {
            //获取微博用户名、uid、token等
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            NSLog(@"username is %@, uid is %@, token is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken);
            //进入你的分享内容编辑页面
            
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:str image:nil location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
                    
                    UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"" message:@"分享成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                }
            }];
        }
    });

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
